找传奇、传世资源到传世资源站!

C# UDP发送消息实例源码(含服务端)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboard
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Net;using System.Net.Sockets;namespace udpSent{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Send(); } public void Send() { Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,ProtocolType.Udp); //起到广播的作用在一个段内如192.168.1.255 都是1 IPAddress broadcast = IPAddress.Parse(this.textBox2.Text.ToString()); // byte[] sendbuf = Encoding.GetEncoding("gb2312").GetBytes(this.textBox1.Text.ToString()); IPEndPoint ep = new IPEndPoint(broadcast, 11000); s.SendTo(sendbuf, ep); Console.WriteLine("Message sent to the broadcast address"); Console.Read(); } private void Form1_Load(object sender, EventArgs e) { } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复